package com.zusmart.core.plugin;

import java.lang.annotation.Annotation;

import com.zusmart.base.activity.support.AbstractActivity;
import com.zusmart.base.util.Assert;
import com.zusmart.base.util.GenericUtils;
import com.zusmart.core.bean.BeanDefinitionRegistry;
import com.zusmart.core.context.ApplicationContext;

public abstract class Plugin extends AbstractActivity<Plugin> {

	private final Annotation annotation;
	private final PluginManager pluginManager;
	private final BeanDefinitionRegistry beanDefinitionRegistry;
	private final ApplicationContext applicationContext;

	public Plugin(Annotation annotation, PluginManager pluginManager, BeanDefinitionRegistry beanDefinitionRegistry, ApplicationContext applicationContext) {
		Assert.isNull(annotation, "plugin annotation must not be null");
		Assert.isNull(pluginManager, "plugin manager must not be null");
		Assert.isNull(beanDefinitionRegistry, "bean definition registry must not be null");
		Assert.isNull(applicationContext, "application context must not be null");
		this.annotation = annotation;
		this.pluginManager = pluginManager;
		this.beanDefinitionRegistry = beanDefinitionRegistry;
		this.applicationContext = applicationContext;
	}

	public final <T extends Annotation> T getAnnotation() {
		return GenericUtils.parse(this.annotation);
	}

	public final PluginManager getPluginManager() {
		return pluginManager;
	}

	public final BeanDefinitionRegistry getBeanDefinitionRegistry() {
		return beanDefinitionRegistry;
	}

	public final ApplicationContext getApplicationContext() {
		return this.applicationContext;
	}

	@Override
	protected Plugin getActivity() {
		return this;
	}

	@Override
	protected void doStart() throws Exception {

	}

	@Override
	protected void doClose() throws Exception {

	}

}